package model

import (
	"time"
)

// ConsumptionRecord 消费记录表
type ConsumptionRecord struct {
	ID                uint64    `json:"id" gorm:"primaryKey;autoIncrement;comment:消费记录ID"`
	OrderNo           string    `json:"orderNo" gorm:"not null;size:32;uniqueIndex;comment:消费单号"`
	MemberID          uint64    `json:"memberId" gorm:"not null;index;comment:会员ID"`
	ConsumptionAmount float64   `json:"consumptionAmount" gorm:"not null;comment:消费金额"`
	FinalAmount       float64   `json:"finalAmount" gorm:"not null;comment:实付金额（折扣后）"`
	ProjectType       int       `json:"projectType" gorm:"not null;comment:消费项目：1理发 2烫染 3护理 4产品"`
	ProjectName       string    `json:"projectName" gorm:"size:100;comment:项目名称"`
	DiscountRate      float64   `json:"discountRate" gorm:"default:1.00;comment:折扣率"`
	BalanceBefore     float64   `json:"balanceBefore" gorm:"not null;comment:消费前余额"`
	BalanceAfter      float64   `json:"balanceAfter" gorm:"not null;comment:消费后余额"`
	OperatorID        uint64    `json:"operatorId" gorm:"not null;comment:操作员ID"`
	Remark            string    `json:"remark" gorm:"type:text;comment:备注"`
	ConsumptionTime   time.Time `json:"consumptionTime" gorm:"comment:消费时间"`
	CreatedAt         time.Time `json:"createdAt" gorm:"comment:创建时间"`

	// 关联字段
	ProjectTypeInfo ProjectType `json:"projectTypeInfo" gorm:"foreignKey:ProjectType;references:TypeCode"`
}

// RechargeRecord 充值记录表
type RechargeRecord struct {
	ID             uint64    `json:"id" gorm:"primaryKey;autoIncrement;comment:充值记录ID"`
	OrderNo        string    `json:"orderNo" gorm:"not null;size:32;uniqueIndex;comment:充值单号"`
	MemberID       uint64    `json:"memberId" gorm:"not null;index;comment:会员ID"`
	RechargeAmount float64   `json:"rechargeAmount" gorm:"not null;comment:充值金额"`
	GiftAmount     float64   `json:"giftAmount" gorm:"default:0.00;comment:赠送金额"`
	FinalAmount    float64   `json:"finalAmount" gorm:"not null;comment:到账金额"`
	PaymentMethod  int       `json:"paymentMethod" gorm:"not null;comment:支付方式：1现金 2微信 3支付宝 4银行卡"`
	BalanceBefore  float64   `json:"balanceBefore" gorm:"not null;comment:充值前余额"`
	BalanceAfter   float64   `json:"balanceAfter" gorm:"not null;comment:充值后余额"`
	OperatorID     uint64    `json:"operatorId" gorm:"not null;comment:操作员ID"`
	Remark         string    `json:"remark" gorm:"type:text;comment:备注"`
	RechargeTime   time.Time `json:"rechargeTime" gorm:"comment:充值时间"`
	CreatedAt      time.Time `json:"createdAt" gorm:"comment:创建时间"`

	// 关联字段
	PaymentMethodInfo PaymentMethod `json:"paymentMethodInfo" gorm:"foreignKey:PaymentMethod;references:MethodCode"`
}

// ProjectType 项目类型表
type ProjectType struct {
	ID          uint64    `json:"id" gorm:"primaryKey;autoIncrement;comment:类型ID"`
	TypeCode    int       `json:"typeCode" gorm:"not null;uniqueIndex;comment:类型编码"`
	TypeName    string    `json:"typeName" gorm:"not null;size:50;comment:类型名称"`
	Price       float64   `json:"price" gorm:"default:0.00;comment:项目价格"`
	Description string    `json:"description" gorm:"size:255;comment:描述"`
	Status      int       `json:"status" gorm:"default:1;comment:状态：1启用 0禁用"`
	CreatedAt   time.Time `json:"createdAt" gorm:"comment:创建时间"`
	UpdatedAt   time.Time `json:"updatedAt" gorm:"comment:更新时间"`
}

// PaymentMethod 支付方式表
type PaymentMethod struct {
	ID          uint64    `json:"id" gorm:"primaryKey;autoIncrement;comment:方式ID"`
	MethodCode  int       `json:"methodCode" gorm:"not null;uniqueIndex;comment:方式编码"`
	MethodName  string    `json:"methodName" gorm:"not null;size:50;comment:方式名称"`
	Description string    `json:"description" gorm:"size:255;comment:描述"`
	Status      int       `json:"status" gorm:"default:1;comment:状态：1启用 0禁用"`
	CreatedAt   time.Time `json:"createdAt" gorm:"comment:创建时间"`
	UpdatedAt   time.Time `json:"updatedAt" gorm:"comment:更新时间"`
}

// DailyStatistics 日统计表
type DailyStatistics struct {
	ID               uint64    `json:"id" gorm:"primaryKey;autoIncrement;comment:统计ID"`
	StatDate         time.Time `json:"statDate" gorm:"not null;uniqueIndex;comment:统计日期"`
	TotalRecharge    float64   `json:"totalRecharge" gorm:"default:0.00;comment:日充值总额"`
	TotalConsumption float64   `json:"totalConsumption" gorm:"default:0.00;comment:日消费总额"`
	NewMembers       int       `json:"newMembers" gorm:"default:0;comment:新增会员数"`
	ActiveMembers    int       `json:"activeMembers" gorm:"default:0;comment:活跃会员数"`
	TotalOrders      int       `json:"totalOrders" gorm:"default:0;comment:总订单数"`
	CreatedAt        time.Time `json:"createdAt" gorm:"comment:创建时间"`
	UpdatedAt        time.Time `json:"updatedAt" gorm:"comment:更新时间"`
}

// MonthlyStatistics 月统计表
type MonthlyStatistics struct {
	ID               uint64    `json:"id" gorm:"primaryKey;autoIncrement;comment:统计ID"`
	StatYear         int       `json:"statYear" gorm:"not null;comment:统计年份"`
	StatMonth        int       `json:"statMonth" gorm:"not null;comment:统计月份"`
	TotalRecharge    float64   `json:"totalRecharge" gorm:"default:0.00;comment:月充值总额"`
	TotalConsumption float64   `json:"totalConsumption" gorm:"default:0.00;comment:月消费总额"`
	NewMembers       int       `json:"newMembers" gorm:"default:0;comment:新增会员数"`
	ActiveMembers    int       `json:"activeMembers" gorm:"default:0;comment:活跃会员数"`
	TotalOrders      int       `json:"totalOrders" gorm:"default:0;comment:总订单数"`
	CreatedAt        time.Time `json:"createdAt" gorm:"comment:创建时间"`
	UpdatedAt        time.Time `json:"updatedAt" gorm:"comment:更新时间"`
}

// TableName 自定义表名
func (ConsumptionRecord) TableName() string {
	return "consumption_records"
}

func (RechargeRecord) TableName() string {
	return "recharge_records"
}

func (ProjectType) TableName() string {
	return "project_types"
}

func (PaymentMethod) TableName() string {
	return "payment_methods"
}

func (DailyStatistics) TableName() string {
	return "daily_statistics"
}

func (MonthlyStatistics) TableName() string {
	return "monthly_statistics"
}
